from core.get_encoding import get_encoding 
import codecs
import argparse

def conv_encoding(file: str, out:str, encoding: str):
  encoding_in = get_encoding(file)
  if encoding_in == encoding:
    print("encoding is same,no conv found")
    return
  with codecs.open(filename=file, mode='rb', encoding=encoding_in, errors='ignore') as fi:
    data = fi.read()
    with open(out, mode='w', encoding=encoding) as fo:
        fo.write(data)
        fo.close()

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("file")
    parser.add_argument("--out")
    parser.add_argument("--encoding", default="utf-8")
    args = parser.parse_args()
    conv_encoding(**vars(args))
